<html>
    <head>

    </head>
    <body>
        <select name="sel" id="id">
            <optgroup label="职业">
                <option value="1">会计</option>
                <option value="2">开发</option>
                <option value="3">测试</option>
            </optgroup>
        </select>
    </body>
    <script>
        let obj = document.getElementById("id");
        obj.onchange = function (){
            alert(obj.innerText);
        }
    </script>
</html>